package com.make.house.api.utils;

import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by xujun on 2017/11/20.
 * 字符串处理的类
 */
public class StringUtils {

    /**
     * 是否为数字
     *
     * @param str
     * @return
     */
    public static boolean isNumeric(String str) {
        Pattern pattern = Pattern.compile("[0-9]*");
        Matcher isNum = pattern.matcher(str);
        if (!isNum.matches()) {
            return false;
        }
        return true;
    }

    /**
     * 是否为空
     *
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        if (str == null || "".equals(str)) {
            return true;
        }
        return false;
    }

    public static String getDateString(int year, int month, int date) {
        return year + int2String(month) + int2String(date);
    }

    public static String getDateString(int year, int month, int date, int hour, int min, int second){
        return getDateString(year, month, date) + int2String(hour) + int2String(min) + int2String(second);
    }

    /**
     * 数据不足2位则补齐
     */
    public static String int2String(int number) {
        return String.format(Locale.getDefault(), "%02d", number);
    }

    /**数据不足3位则补齐*/
    public static String int2String3(int number){
        return String.format(Locale.getDefault(), "%03d", number);
    }

    public static String changeDeafultUserName(String userName) {
        if (isEmpty(userName)) {
            return "";
        }
        return userName.replaceAll(userName.substring(3, 6), "*****");
    }
}
